package com.zhongwang.mms.module.half.service;

import com.zhongwang.mms.gen.entity.User;
import com.zhongwang.mms.module.half.dao.HInventoryDao;
import com.zhongwang.mms.module.half.model.HalInProReportExport;
import com.zhongwang.mms.util.FileUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @description:成品库统计报表
 * @author: th
 * @time: 2020/7/17 16:04
 */
@Service
public class HReportFormsService {

    @Autowired
    private HInventoryDao hInventoryDao;
    @Value("${user.upload.path}")
    private String uploadPath;

    /**
     *制作件在库项目明细
     * @param param
     * @return
     */
    public List<HalInProReportExport> findHalInProReportList(HalInProReportExport param) {
        return hInventoryDao.findHalInProReportList(param);
    }

    /**
     * 制作件在库项目明细导出
     * @param response
     * @param param
     */
    public void halInProReportExcel(HttpServletResponse response, HalInProReportExport param) {
        List<HalInProReportExport> model = hInventoryDao.findHalInProReportList(param);
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        String path = uploadPath + user.getAccount() + "/";
        FileUtils.export(path, "制作件在库项目明细.xls", HalInProReportExport.class, "sheet1", model, response);
    }
}
